#include <stdio.h>
#include <gtk/gtk.h>

#include "interface.h"
#include "common.h"
#include "callbacks.h"
#include "global_var.h"

GtkWidget *create_login()
{
		GtkWidget *label1;
		GtkWidget *label2;
		GtkWidget *login_button;
		GtkWidget *regist_button;
		GtkWidget *vbox1;
		GtkWidget *hbox1;
		GtkWidget *hbox2;
		GtkWidget *hbox3;

		login_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
		gtk_window_set_title(GTK_WINDOW(login_window),"登陆");
		gtk_window_set_default_size(GTK_WINDOW(login_window),200,140);
		gtk_window_set_position(GTK_WINDOW(login_window),GTK_WIN_POS_CENTER);
		gtk_window_set_icon(GTK_WINDOW(login_window),create_pixbuf("icon.jpg"));
		gtk_window_set_resizable(GTK_WINDOW(login_window),FALSE);
		g_signal_connect(G_OBJECT(login_window),"delete_event",G_CALLBACK(delete_event),NULL);
		g_signal_connect(G_OBJECT(login_window),"destroy",G_CALLBACK(destroy),NULL);

		vbox1 = gtk_vbox_new(FALSE,0);
		gtk_widget_show(vbox1);
		gtk_container_add(GTK_CONTAINER(login_window),vbox1);

		hbox1 = gtk_hbox_new(FALSE,0);
		gtk_widget_show(hbox1);
		gtk_box_pack_start(GTK_BOX(vbox1),hbox1,FALSE,FALSE,0);

		label1 = gtk_label_new("用户名：");
		gtk_widget_show(label1);
		gtk_box_pack_start(GTK_BOX(hbox1),label1,FALSE,FALSE,0);
		gtk_widget_set_size_request(label1,50,45);
		
		login_user_entry = gtk_entry_new();
		gtk_widget_show(login_user_entry);
		gtk_box_pack_start(GTK_BOX(hbox1),login_user_entry,FALSE,FALSE,0);

		hbox2 = gtk_hbox_new(FALSE,0);
		gtk_widget_show(hbox2);
		gtk_box_pack_start(GTK_BOX(vbox1),hbox2,FALSE,FALSE,0);

		label2 = gtk_label_new("密   码：");
		gtk_widget_show(label2);
		gtk_box_pack_start(GTK_BOX(hbox2),label2,FALSE,FALSE,0);
		gtk_widget_set_size_request(label2,50,45);

		login_pwd_entry = gtk_entry_new();
		gtk_entry_set_visibility(GTK_ENTRY(login_pwd_entry),FALSE);
		gtk_widget_show(login_pwd_entry);
		gtk_box_pack_start(GTK_BOX(hbox2),login_pwd_entry,FALSE,FALSE,0);

		hbox3 = gtk_hbox_new(FALSE,0);
		gtk_widget_show(hbox3);
		gtk_box_pack_start(GTK_BOX(vbox1),hbox3,FALSE,FALSE,0);

		login_button = gtk_button_new_with_label("登陆");
		gtk_widget_show(login_button);
		gtk_box_pack_start(GTK_BOX(hbox3),login_button,FALSE,FALSE,0);
		gtk_widget_set_size_request(login_button,80,35);
		g_signal_connect(G_OBJECT(login_button),"clicked",G_CALLBACK(login_button_clicked),NULL);

		regist_button = gtk_button_new_with_label("注册");
		gtk_widget_show(regist_button);
		gtk_box_pack_end(GTK_BOX(hbox3),regist_button,FALSE,FALSE,0);
		gtk_widget_set_size_request(regist_button,80,35);
		g_signal_connect(G_OBJECT(regist_button),"clicked",G_CALLBACK(regist_button_clicked),NULL);
		
		return login_window;
		

}


GtkWidget *create_regist()
{
		GtkWidget *regist_submit_button;
		GtkWidget *cancel_button;
		GtkWidget *label1;
		GtkWidget *label2;
		GtkWidget *label3;
		GtkWidget *vbox1;
		GtkWidget *hbox1;
		GtkWidget *hbox2;
		GtkWidget *hbox3;
		GtkWidget *hbox4;
		
		regist_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
		gtk_window_set_title(GTK_WINDOW(regist_window),"用户注册");
		gtk_window_set_default_size(GTK_WINDOW(regist_window),200,300);
		gtk_window_set_position(GTK_WINDOW(regist_window),GTK_WIN_POS_CENTER);
		gtk_window_set_icon(GTK_WINDOW(regist_window),create_pixbuf("icon2.jpg"));
		gtk_window_set_resizable(GTK_WINDOW(regist_window),FALSE);
		g_signal_connect(G_OBJECT(regist_window),"delete_event",G_CALLBACK(delete_event),NULL);
		g_signal_connect(G_OBJECT(regist_window),"destroy",G_CALLBACK(destroy_widget),NULL);

		vbox1 = gtk_vbox_new(FALSE,0);
		gtk_widget_show(vbox1);
		gtk_container_add(GTK_CONTAINER(regist_window),vbox1);

		hbox1 = gtk_hbox_new(FALSE,0);
		gtk_widget_show(hbox1);
		gtk_box_pack_start(GTK_BOX(vbox1),hbox1,FALSE,FALSE,0);

		label1 = gtk_label_new("用 户 名：");
		gtk_widget_show(label1);
		gtk_box_pack_start(GTK_BOX(hbox1),label1,FALSE,FALSE,0);
		gtk_widget_set_size_request(label1,60,45);

		regist_user_entry = gtk_entry_new();
		gtk_widget_show(regist_user_entry);
		gtk_box_pack_start(GTK_BOX(hbox1),regist_user_entry,FALSE,FALSE,0);

		hbox2 = gtk_hbox_new(FALSE,0);
		gtk_widget_show(hbox2);
		gtk_box_pack_start(GTK_BOX(vbox1),hbox2,FALSE,FALSE,0);
		
		label2 = gtk_label_new("密      码：");
		gtk_widget_show(label2);
		gtk_box_pack_start(GTK_BOX(hbox2),label2,FALSE,FALSE,0);
		gtk_widget_set_size_request(label2,60,45);

		regist_pwd_entry = gtk_entry_new();
		gtk_entry_set_visibility(GTK_ENTRY(regist_pwd_entry),FALSE);
		gtk_widget_show(regist_pwd_entry);
		gtk_box_pack_start(GTK_BOX(hbox2),regist_pwd_entry,FALSE,FALSE,0);

		hbox3 = gtk_hbox_new(FALSE,0);
		gtk_widget_show(hbox3);
		gtk_box_pack_start(GTK_BOX(vbox1),hbox3,FALSE,FALSE,0);

		label3 = gtk_label_new("确认密码：");
		gtk_widget_show(label3);
		gtk_box_pack_start(GTK_BOX(hbox3),label3,FALSE,FALSE,0);
		gtk_widget_set_size_request(label3,60,45);

		regist_pwd_again_entry = gtk_entry_new();
		gtk_entry_set_visibility(GTK_ENTRY(regist_pwd_again_entry),FALSE);
		gtk_widget_show(regist_pwd_again_entry);
		gtk_box_pack_start(GTK_BOX(hbox3),regist_pwd_again_entry,FALSE,FALSE,0);

		hbox4 = gtk_hbox_new(FALSE,0);
		gtk_widget_show(hbox4);
		gtk_box_pack_start(GTK_BOX(vbox1),hbox4,FALSE,FALSE,0);

		regist_submit_button = gtk_button_new_with_label("提交");
		gtk_widget_show(regist_submit_button);
		gtk_box_pack_start(GTK_BOX(hbox4),regist_submit_button,FALSE,FALSE,0);
		gtk_widget_set_size_request(regist_submit_button,80,35);
		g_signal_connect(G_OBJECT(regist_submit_button),"clicked",G_CALLBACK(regist_submit_button_clicked),NULL);

		cancel_button = gtk_button_new_with_label("取消");
		gtk_widget_show(cancel_button);
		gtk_box_pack_end(GTK_BOX(hbox4),cancel_button,FALSE,FALSE,0);
		gtk_widget_set_size_request(cancel_button,80,35);
		g_signal_connect_swapped(G_OBJECT(cancel_button),"clicked",G_CALLBACK(destroy_widget),regist_window);

		return regist_window;
}


GtkWidget *create_dialog_tips(gchar *str)
{
		GtkWidget *dialog1;
		GtkWidget *dialog_vbox1;
		GtkWidget *label1;
		GtkWidget *dialog_action_area1;
		GtkWidget *okbutton1;
		 
		dialog1 = gtk_dialog_new ();
		gtk_window_set_title (GTK_WINDOW (dialog1), "提示信息");
		gtk_window_set_default_size (GTK_WINDOW (dialog1), 200, 100);
		gtk_window_set_type_hint (GTK_WINDOW (dialog1), GDK_WINDOW_TYPE_HINT_DIALOG);
		 
		dialog_vbox1 = GTK_DIALOG (dialog1)->vbox;
		gtk_widget_show (dialog_vbox1);
		 
		label1 = gtk_label_new (str);
		gtk_widget_show (label1);
		gtk_box_pack_start (GTK_BOX (dialog_vbox1), label1, FALSE, FALSE, 0);
		 
		dialog_action_area1 = GTK_DIALOG (dialog1)->action_area;
		gtk_widget_show (dialog_action_area1);
		gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
		 
		okbutton1 = gtk_button_new_from_stock ("gtk-ok");
		gtk_widget_show (okbutton1);
		gtk_dialog_add_action_widget (GTK_DIALOG (dialog1), okbutton1, GTK_RESPONSE_OK);
		GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
		g_signal_connect(G_OBJECT(okbutton1),"clicked",G_CALLBACK(okbutton1_clicked),(gpointer *)dialog1);
		
		return dialog1;
}




















